import axios from "axios"
import * as types from "../actionTypes"
const setArticle = (payload) => ({ type: types.GETARTICLE, payload })

// thunk action
export const getArticle = (channel_id) => {
  return async (dispatch) => {
    const {
      data: {
        data: { results },
      },
    } = await axios({
      url: "http://toutiao.itheima.net/v1_0/articles",
      params: {
        channel_id,
        timestamp: Date.now(),
      },
    })
    // 设置数据到redux中
    dispatch(setArticle(results)) // 将文章数据派发到 reducer
  }
}
